﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using ASPNETVN.PORTAL.Components.Helpers;
using ASPNETVN.PORTAL.Components.UI;
using ASPNETVN.PORTAL.Modules.SCHEDULE.Components;
using ASPNETVN.PORTAL.Components.Share.Controls;
using ASPNETVN.PORTAL.Components.Share;

namespace ASPNETVN.PORTAL.Modules.SCHEDULE.Controls
{
    public partial class Item : ModulePage
    {        
        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack == false)
            {                
                cbCategory.DataSource = ASPNETVN.PORTAL.Components.Share.Department.SelectAll(this.ModuleID);
                cbCategory.DataBind();
                //BindingData();                
            }
        }

        protected string GetAddEditItemUrl(int itemID)
        {
            Hashtable settings = this.Settings;
            return HttpUrlBuilder.BuildAddEditUrl(this.ModuleID, itemID, "AddEditItem", "");
        }

        protected static string GetImageURL(string imageUrl)
        {
            if (imageUrl.Length == 0) return "";
            return "~/Modules/Link/Icons/" + imageUrl;
        }
        protected string GetEditURL(int itemID)
        {
            return HttpUrlBuilder.BuildAddEditUrl(this.ModuleID, itemID, "AddEditItem", "");
        }
        protected string GetDetailURL(int itemID)
        {
            return HttpUrlBuilder.BuildModulePageUrl(this.ModuleID, itemID, ModulePages.Detail);
        }          

        protected void btnFilter_Click(object sender, EventArgs e)
        {
            ObjectDataSource1.TypeName = "ASPNETVN.PORTAL.Modules.SCHEDULE.Components.Items";
            ObjectDataSource1.SelectMethod = "SelectDynamic";
            int DepartmentID = 0;
            DepartmentID = Convert.ToInt32(this.cbCategory.SelectedValue.ToString());
            Department department = new Department();
            department = Department.Load(DepartmentID);            
            hfDepartmentID.Value = department.ParentID == 0 ? "1=1" : "DepartmentID=" + this.cbCategory.SelectedValue.ToString();
            GridView1.DataSourceID = "ObjectDataSource1";
            GridView1.DataBind();

        }

        //protected void BindingData()
        //{
        //    GridView1.DataSource = ASPNETVN.PORTAL.Modules.SCHEDULE.Components.Items.SelectDynamic("1=1", "");
        //    GridView1.DataBind();
        //}

        protected void GridView1_PageIndexChanged(object sender, EventArgs e)
        {
            GridView1.SelectedIndex = -1;
        }
    }
}